package example.lesson04_02;

import java.util.Arrays;

public class TestArray {

    public static void main(String[] args) {


        //int a[3]
        //数组的创建，数组是对象
        int[] intArray = new int[3];
        intArray[0] = 1;intArray[1] = 3;intArray[2] = 2;
        //int[]intArray={1,2,3}

        //格式化代码：Alt+Ctrl+Shift+l
        //遍历数组
        for (int i = 0; i < intArray.length; i++) {
            System.out.println(intArray[i] + ",");
        }
        //排序
        Arrays.sort(intArray);
        System.out.println("\n排序后:");

        //增强型for循环，只读性遍历
        for (int elem : intArray) {
            System.out.println(elem + ",");
        }

        //引用型数组，这条语句创建了一个Person[]类型对象，没有创建任何Person类型的对象
        Person[] objArray = new Person[3];
        objArray[0]=new Person(20,"ZhangSan");
        objArray[1]=new Person(40,"LiSi");
        objArray[2]=new Person(30,"WangWu");

        for (Person person : objArray){
            System.out.println(person + ",");
        }

    }

}


    class Person {
        public int age;

        public String name;

        Person(int age, String name) {

            this.age = age;
            this.name = name;
        }

        public String toString() {
            return "age:" + age + ", name:" + name;
        }

    }



